<?php
/**
 * The Template for displaying all single posts.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */

get_header(); ?>

		<div id="container">
			<div id="content" role="main">
				<div id="slides">
				<!--
				<div class="singleslide-btn btnNext"><a class="btnNext" href="#">Next</a></div>
				<div class="singleslide-btn btnPrev"><a class="btnPrev" href="#">Prev</a></div>
				-->
				<div class="slides_container">
				<?php
				// Cache the current post_id
				
				$current_post_id = $post->ID;
				
				$the_cats = get_the_category($post->ID);
				$curren_cat = $the_cats[0]->term_id;
				
				if (is_single()) {
					query_posts( 'cat='.$curren_cat);
				}
				else if(is_category()) {
					$cat_id = get_query_var('cat');
					query_posts( 'cat='. $cat_id);
				}

				/*
				
				$large_image_url = get_bloginfo('stylesheet_directory')."/images/home-default-image.png";
				if ( has_post_thumbnail()) {
					$large_image_urls = wp_get_attachment_image_src( get_post_thumbnail_id(), 'home-thumb');
					$large_image_url = $large_image_urls[0];
				}
				
				*/
				
				$post_array = null;
				
				$current_single_idx = 1;
				?>
				
				<?php while ( have_posts() ) : the_post(); ?>
					<?php
						$post_array[$wp_query->current_post + 1] =  $post->ID;
					
						if($post->ID == $current_post_id) {
							$current_single_idx = $wp_query->current_post + 1;
							// echo $current_single_idx;
						}
						
					?>
					<div id="post-<?php echo ($wp_query->current_post + 1) . '-' . $post->ID ; ?>">
						<div class="col-1">
							<img src="<?php bloginfo('stylesheet_directory'); ?>/images/loading8.gif" alt=""/>
						</div>
						<div class="col-2">

						</div>
					</div>
					

				<?php endwhile; // end of the loop. ?>
				
				<?php
					js_localize('posts_index', array('default_img' => get_bloginfo('stylesheet_directory')."/images/home-default-image.png", 'data' => $post_array, 'current_idx' => $current_single_idx));
				?>
				<?php wp_reset_query(); ?>
				</div> <!-- slides -->
				</div> <!-- slides -->
			</div><!-- #content -->
		</div><!-- #container -->
		<script>
            jQuery(function($){
				
				jsonGetPostContent(posts_index.current_idx, $("#slides"));

				/*
				console.info("posts_index.current_idx");
				console.info(posts_index.current_idx);
				*/
            	jQuery('#slides').slides({
    				preload: true,
					// next : 'btnNext',
					// prev : 'btnPrev',
					generateNextPrev  : true,
    				//generateNextPrev: true,
    				// start: posts_index.current_idx,
    				start: posts_index.current_idx,
					animationComplete: function(current){
						// console.info("animationComplete");
						jsonGetPostContent(current, $("#slides"));
					}
					
    			});
				
				
    		});
        </script>

<?php get_sidebar('single'); ?>
<?php get_footer(); ?>
